package com.tencent.cloud.uikit.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tencent.cloud.iov.util.ViewStateUtils;
import com.tencent.cloud.uikit.R;

/**
 * @author showxiao
 * @date 2018/9/23
 */
public class FixedNoticeView extends RelativeLayout {

    private TextView mNoticeTextView;

    public FixedNoticeView(Context context) {
        super(context);
    }

    public FixedNoticeView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public FixedNoticeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mNoticeTextView = findViewById(R.id.tv_fix_notice_text);

        View closeView = findViewById(R.id.tv_fix_notice_close);
        ViewStateUtils.setUpViewPressState(closeView);
        closeView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ViewParent parent = getParent();
                if (parent instanceof ViewGroup) {
                    ((ViewGroup) parent).removeView(FixedNoticeView.this);
                }
            }
        });
    }

    public void setNoticeText(CharSequence text) {
        mNoticeTextView.setText(text);
    }
}
